function CreateOrderAssistant(argFromPusher) {
}

CreateOrderAssistant.prototype = {
	country: null,
	zone: null,
	setup: function() {
		Ares.setupSceneAssistant(this);
		var addr = null;
		if( addr = getStorageObject("address" + user.uid)){
			this.$.firstBox.setValue(addr.first);
			this.$.lastBox.setValue(addr.last);
			this.$.companyBox.setValue(addr.company);
			this.$.streetBox.setValue(addr.street);
			this.$.cityBox.setValue(addr.city);
			if(addr.country){
				this.country = addr.country;
				this.$.countryLbl.setLabel(addr.country.country_name);
			}
			if(addr.zone){
				this.zone = addr.zone;
				this.$.zoneLbl.setLabel(addr.zone.zone_name);
			}
			this.$.postalBox.setValue(addr.postal);
			this.$.phoneBox.setValue(addr.phone);
		}
	},
	cleanup: function() {
		Ares.cleanupSceneAssistant(this);
	},
	activate: function(event) {
		if(!event) return;
		if(event.country){
			this.country = event.country;
			this.$.countryLbl.setLabel(event.country.country_name);
		}
		else if(event.zone){
			this.zone = event.zone;
			this.$.zoneLbl.setLabel(event.zone.zone_name);
			
		}
	},
	button1Tap: function(inSender, event) {
		var message = this.validate();
		if(message != ""){
			myAlert(this, message)
			return;
		}
			
		var order = {
			products: getCartList(),
			comment: this.$.commentBox.getValue(),
			uid: user.uid,
			primary_email: user.mail,
			billing_first_name: this.$.firstBox.getValue(),
			billing_last_name: this.$.lastBox.getValue(), 
			billing_company: this.$.companyBox.getValue(),
			billing_street1: this.$.streetBox.getValue(),
			billing_street2: '', 
			billing_city: this.$.cityBox.getValue(),
			billing_country: this.country.country_id,
			billing_zone: this.zone.zone_id, 
			billing_postal_code: this.$.postalBox.getValue(),
			billing_phone: this.$.phoneBox.getValue()
		};
		drupalService('uc_order.createOrder', {order: order}, this, function(data) {
			emptyCart();
			myAlert(this, data, function(){
				Mojo.Controller.stageController.popScenesTo("home");
			}, null, null, null, true);
		}.bind(this));
	},
	label1Tap: function(inSender, event) {
		Mojo.Controller.stageController.pushScene("countriesList");
	},
	label2Tap: function(inSender, event) {
		if(this.country != null)
			Mojo.Controller.stageController.pushScene("zonesList", {country_id: this.country.country_id});
		else
			myAlert(this, "Please select country.");
	},
	validate: function() {
		var invalidFields = [];
		if(this.$.firstBox.getValue().trim() == "")
			invalidFields.push("First Name");
		if(this.$.lastBox.getValue().trim() == "")
			invalidFields.push("Last Name");
		if(this.$.streetBox.getValue().trim() == "")
			invalidFields.push("Address");
		if(this.$.cityBox.getValue().trim() == "")
			invalidFields.push("City");
		if(this.country == null)
			invalidFields.push("Country");
		if(this.zone == null)
			invalidFields.push("Zone");
		if(this.$.postalBox.getValue().trim() == "")
			invalidFields.push("Postal Code");
		
		if(invalidFields.length == 0) return "";
		else
			return "Please fill " + invalidFields.join(", ");
		
	}
};